Add cppcheck static analysis for the NIF - #207
Merged
Merged
Conversation
Wire cppcheck over the C++ NIF sources in c_src/. Add a self-contained `make cppcheck` target so developers can run it locally without a built libmlx or the BEAM toolchain — it analyses only our own tree and suppresses the third-party headers (<mlx/...>, <fine.hpp>, <erl_nif.h>) it can't see. `passedByValueCallback` is suppressed because every NIF entry point takes its container args by value by Fine's FINE_NIF convention. Add a macOS CI job that installs cppcheck via brew and runs the same target, so the check gates PRs on the platform the NIF ships on. Document `make cppcheck` under Local debugging in MAINTAINING.md.
cppcheck (uninitMemberVarNoCtor) flags the scalar `opcode` member as having no initializer while its sibling container members self-init. Every real construction aggregate-initializes all fields, so this was never a live bug, but value-initializing it gives a default-constructed instr a defined opcode and keeps the check clean. Surfaced by the brew cppcheck (2.21) in CI, which enables this check where the older local 2.13 did not.
ausimian
force-pushed
the
claude/nif-static-analysis-tools-t3rmhg
branch
from
July 20, 2026 19:27
158d675 to
752353b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wire cppcheck over the C++ NIF sources in
c_src/. Add a self-containedmake cppchecktarget so developers can run it locally without a builtlibmlx or the BEAM toolchain — it analyses only our own tree and
suppresses the third-party headers (
<mlx/...>,<fine.hpp>,<erl_nif.h>)it can't see.
passedByValueCallbackis suppressed because every NIFentry point takes its container args by value by Fine's
FINE_NIFconvention.
Add a macOS CI job that installs cppcheck via brew and runs the same
target, so the check gates PRs on the platform the NIF ships on.
Document
make cppcheckunder Local debugging in MAINTAINING.md.Also value-initialize
CompiledInstr::opcode: cppcheck'suninitMemberVarNoCtorflags the scalar member as having no initializerwhile its sibling containers self-init. Every real construction
aggregate-initializes all fields, so this was never a live bug, but
value-initializing keeps the check clean.